package Demo2;

import java.util.Arrays;
import java.util.Random;

public class Test {

    public static void orderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }
    public static void notOrderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length-i;
        }
    }
    public static void orderArrayRandom(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }
    public static void testInsertSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序用时"+(endTime-startTime));
    }
    public static void testShellSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序用时"+(endTime-startTime));
    }
    public static void testSelectSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序用时"+(endTime-startTime));
    }
    public static void testHeapSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序用时"+(endTime-startTime));
    }
    public static void testQuickSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序用时"+(endTime-startTime));
    }
    public static void testmergeQuickSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序用时"+(endTime-startTime));
    }
    public static void main2(String[] args) {
        int[] arr = new int[10_0000];
//        orderArray(arr);
          notOrderArray(arr);
     //  orderArrayRandom(arr);
//        testInsertSort(arr);
//        testShellSort(arr);
//        testSelectSort(arr);
//        testHeapSort(arr);
//        testQuickSort(arr);
        testmergeQuickSort(arr);
    }
    public static void main(String[] args) {
        int[] arr = {1,21,32,4,5};
//        Sort.insertSort(arr);
//        System.out.println(Arrays.toString(arr));
//        Sort.shellSort(arr);
//        System.out.println(Arrays.toString(arr));
//        Sort.selectSort(arr);
//        System.out.println(Arrays.toString(arr));
//        Sort.selectSort2(arr);
//        System.out.println(Arrays.toString(arr));
//        Sort.heapSort(arr);
//        System.out.println(Arrays.toString(arr));
//        Sort.bubleSort(arr);
//       System.out.println(Arrays.toString(arr));
//        Sort.quickSort(arr);
//        System.out.println(Arrays.toString(arr));
//        Sort.quickSortNor(arr);
        Sort.mergeSort2(arr);
        System.out.println(Arrays.toString(arr));

    }
}
